home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-05 / drivers2.zip / TIMEOUT.ASM < prev    next >
Assembly Source File  |  1992-01-17  |  984b  |  35 lines

  1. ;put into the public domain by Russell Nelson, nelson@crynwr.com
  2.  
  3. ;we read the timer chip's counter zero.  It runs freely, counting down
  4. ;from 65535 to zero.  Whenever the count is above the old count, the
  5. ;timer must have wrapped around.  When that happens, we count down a tick.
  6.  
  7. timeout        dw    ?        ;number of ticks to wait.
  8. timeout_counter    dw    ?        ;old counter zero value.
  9.  
  10. set_timeout:
  11. ;enter with ax = number of ticks (36.4 ticks per second).
  12.     inc    ax            ;the first times out immediately.
  13.     mov    cs:timeout,ax
  14.     mov    cs:timeout_counter,0
  15.     ret
  16.  
  17.  
  18. do_timeout:
  19. ;call periodically when checking for timeout.  Returns nz if we haven't
  20. ;timed out yet.
  21.     mov    al,0            ;latch counter zero.
  22.     out    43h,al
  23.     in    al,40h            ;read counter zero.
  24.     mov    ah,al
  25.     in    al,40h
  26.     xchg    ah,al
  27.     cmp    ax,cs:timeout_counter    ;is the count higher?
  28.     mov    cs:timeout_counter,ax
  29.     jbe    do_timeout_1        ;no.
  30.     dec    cs:timeout        ;Did we hit the timeout value yet?
  31.     ret
  32. do_timeout_1:
  33.     or    sp,sp            ;ensure nz.
  34.     ret
  35.